# -*- coding:UTF-8 -*-
'''
开发环境：PyCharm
创建日期：2025/8/6 17:06
作   者：新启典学苑-樱桃
描   述：
'''
from time import sleep

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Edge()  # 创建edge浏览器对象
driver.get("http://www.baidu.com")

toolsbar = driver.find_element(By.ID, "s-top-left")
es = toolsbar.find_elements(By.TAG_NAME, "a")
for i in range(4):
    es[i].click()

hds = driver.window_handles  # 获取所有窗口的句柄
print(hds)
print(len(hds))  # 5
print("当前窗口的句柄：", driver.current_window_handle)
print("当前窗口的标题：", driver.title)  # 百度首页
# driver.close()

driver.switch_to.window(hds[-1])  # 切换窗口
print("当前窗口的标题：", driver.title)

print("*" * 100)
for i in range(len(hds)):
    driver.switch_to.window(hds[i])
    print("当前窗口的标题：", driver.title)
    if driver.title == "百度新闻——海量中文资讯平台":
        print("-------------")

sleep(10)
